package levev01.one;

import java.io.File;

public class PrintDir {
    private static   int count;
    public void printDir(File file) {
        if (file.isDirectory()) {
            File[] files = file.listFiles();
            for (File file1 : files) {
                if (file1.isFile()) {
                    //是文件
                    System.out.println("文件大小为:" + file1.length());
                    //输出文件绝对路径
                    System.out.println("文件绝对路径为:" + file1.getAbsolutePath());
                    count++;
                } else {
                    //是文件夹
                    System.out.println("文件夹绝对路径是:" + file1.getAbsolutePath());
                    // 继续遍历,调用printDir,形成递归
                    printDir(file1);
                }
            }
        } else {
            //是文件
            System.out.println("文件大小为:" + file.length());
            //输出文件绝对路径
            System.out.println("文件大小为:" + file.getAbsolutePath());
            count++;
        }
        System.out.println("文件个数为:"+count );
    }
}

